package com.newcoder.community.config;

import com.newcoder.community.controller.interceptor.AlphaInterceptor;
import com.newcoder.community.controller.interceptor.LoginRequiredInterceptor;
import com.newcoder.community.controller.interceptor.LoginTicketInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置类
 *
 * ClassName:WebMvcConfig
 * Package:com.newcoder.community.config
 *
 * @author: pf
 * @date: 2021/11/29-11:25
 */

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private AlphaInterceptor alphaInterceptor;

    @Autowired
    private LoginTicketInterceptor loginTicketInterceptor;

    @Autowired
    private LoginRequiredInterceptor loginRequiredInterceptor;

    // 实现接口的方法（根据需求），注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

//        registry.addInterceptor(alphaInterceptor)
//                .excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png", "/**/*.jpg", "/**/*.jpeg") // 排除不需要拦截的选项
//                .addPathPatterns("/register", "/login");// 明确需要拦截的路径

        registry.addInterceptor(loginTicketInterceptor)
                .excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png", "/**/*.jpg", "/**/*.jpeg"); // 排除不需要拦截的选项

        registry.addInterceptor(loginRequiredInterceptor)
                .excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png", "/**/*.jpg", "/**/*.jpeg");

    }
}
